package com.alibaba.cirtus.ots.application.adapter.ability.facade.service.retry;

import com.alibaba.cz.base.tool.Nullable;
import com.alibaba.fastjson.JSONObject;
import com.epoch.app.otsapplicationadaptersdk.sap.*;
import org.junit.Test;
import tools.Resource;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

public class TestInvoiceRepairTool {
    /**
     * file: input.json,result.json
     * to compare this data which exclude in input.json
     *for invoice failed process data
     * */
    @Test
    public void main() {
        String inputJson = Resource.getResourceAsStringByClass(this.getClass(), "/input.json", "utf-8");
        String resultJson = Resource.getResourceAsStringByClass(this.getClass(), "/result.json", "utf-8");
        MnSapIf016Request inputObj = JSONObject.parseObject(inputJson, MnSapIf016Request.class);
        MnSapCommResponse outputObj = JSONObject.parseObject(resultJson, MnSapCommResponse.class);
        Map<String, List<MnSapIf016Detail>> collect = inputObj.getData().stream().collect(Collectors.toMap(MnSapIf016SDO::getHeaderKey, MnSapIf016SDO::getItems));
        Map<String, List<MnSapCommDetail>> collect1 = outputObj.getData().stream().collect(Collectors.toMap(MnSapCommSDO::getHeaderKey, MnSapCommSDO::getItem));
        for (Map.Entry<String, List<MnSapIf016Detail>> stringListEntry : collect.entrySet()) {
            String key = stringListEntry.getKey();
            List<MnSapIf016Detail> value = stringListEntry.getValue();
            List<MnSapCommDetail> mnSapCommDetails = collect1.get(key);
            Map<String, String> collect2 = Nullable.stream(mnSapCommDetails).collect(Collectors.toMap(MnSapCommDetail::getItemKey, MnSapCommDetail::getStatus));

            for (MnSapIf016Detail mnSapIf016Detail : value) {
                String orderLineId = mnSapIf016Detail.getOrderLineId();
                if (!collect2.containsKey(orderLineId)||!"S".equals(collect2.get(orderLineId))) {
                    System.out.println(key+"\t"+orderLineId);
                }
            }

        }



    }
}
